<?php
set_include_path('../Library:../Application');
require('Zend/Loader/Autoloader.php');
$loader = Zend_Loader_Autoloader::getInstance();
$loader->registerNamespace(array('Zend_','Model_','BookHerd_'));

require('creds.php');

// Make a database connection and store it in the registry.
$zf_db = Zend_Db::factory('Pdo_Mysql', array(
    'host'     => 'books',
    'username' => 'bookherd',
    'password' => 'bookherd',
    'dbname'   => 'bookherd',
));
Zend_Registry::set('database', $zf_db);
 
// Set this database as the default adapter.
Zend_Db_Table_Abstract::setDefaultAdapter($zf_db);



/* application starts here */
$zxingurl="http://zxing.appspot.com/scan?ret=http%3A%2F%2F".$_SERVER["HTTP_HOST"]."%2F%3Fquery%3D%7BCODE%7D&SCAN_FORMATS=EAN_8,EAN_13";

if( isset( $_REQUEST["query"] ) ){
	$request = $_REQUEST["query"];
	
	$book = new Model_Book();
	
	try { 
		$book->insert( array( "isbn" => $request ) );
	}
	catch( Exception $e ){
		error_log("Failed to insert " . $request . ": " . $e->getMessage );
	}
}
/* forward to the barcode reader */
header("Location: $zxingurl");



